<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:p="http://primefaces.org/ui"
                template="./../../template/tagedu.xhtml">

    <ui:define name="title">
        <title><h:outputText value="HB - TAG"/></title>
    </ui:define>

    <ui:define name="content">
        <h:outputText styleClass="enrollmentName" value="Medida HB"/>
        <h:form id="hbForm">
            <p:messages id="message" autoUpdate="true" showDetail="true"/>
            <h:panelGroup id="details" >
                <div class="input-list">
                <h:outputLabel styleClass="label" for="hbCampaign" value="Campanha: "/>
                <p:selectOneMenu id="hbCampaign" value="#{hbBean.campaign}"  converter="campaignC">
                    <f:selectItem value="#{null}" itemLabel="Selecione uma campanha:"/>
                    <f:selectItems value="#{hbBean.campaignList}" var="c" itemLabel="#{c.name}" itemValue="#{c}" />
                    <p:ajax update="dataTableAlunos bottomSave hbUnity" process="@this"/>
                </p:selectOneMenu>
                </div>
                <div class="input-list">
                <h:outputLabel styleClass="label" value="Ano: "/>
                <p:spinner value="#{hbBean.year}" min="#{hbBean.actualYear-1}" max="#{hbBean.actualYear}" size="4">
                    <f:validator validatorId="yearV"/>
                    <f:attribute name="minimo" value="#{(hbBean.actualYear-1).toString()}"/>
                    <f:attribute name="maximo" value="#{(hbBean.actualYear).toString()}"/>
                    <p:ajax update="hbUnity" process="@this"/>  
                </p:spinner>
                </div>
                <div class="input-list">
                <h:outputLabel styleClass="label" for="hbUnity" value="Turma: "/>
                <p:selectOneMenu id="hbUnity" value="#{hbBean.unity}" converter="unityC">
                    <f:selectItem value="#{null}" itemLabel="Selecione uma unidade:"/>
                    <f:selectItems value="#{hbBean.unityList}" var="u" itemLabel="#{u.name}" itemValue="#{u}"/>
                    <p:ajax update="bottomSave dataTableAlunos" process="@this" listener="#{hbBean.loadDataTable()}"/>    
                </p:selectOneMenu>
                </div>
                
                <div class="clear"></div>
                
                <br/>
                
                <p:dataTable id="dataTableAlunos" var="patient" value="#{hbBean.humanHbMeasures}">
                    <f:facet name="header">Alunos</f:facet>
                    
                    <p:column headerText="Nome">
                        <h:outputText value="#{patient.human.name}"/>
                    </p:column>
                    
                    <p:column headerText="HB1 - Taxa de Hemoglobina">
                        <center>
                            <p:inplace id="ajaxInplace1" editor="true">  
                                <p:inputText value="#{patient.hb1.hemoglobineTax}" size="5" label="HB1"
                                              required="true" disabled="#{!patient.hasHb1()}"/>
                            </p:inplace>
                        </center>
                    </p:column>
                    
                    <p:column headerText="HB2 - Taxa de Hemoglobina">
                        <center>
                            <p:inplace id="ajaxInplace2" editor="true">  
                                <p:inputText value="#{patient.hb2.hemoglobineTax}" size="5" label="HB1"
                                             required="true" disabled="#{!patient.hasHb2()}"/>
                            </p:inplace>
                        </center>
                    </p:column>
                    
                    <p:column headerText="HB3 - Taxa de Hemoglobina">
                        <center>
                            <p:inplace id="ajaxInplace3" editor="true">
                                <p:inputText value="#{patient.hb3.hemoglobineTax}" size="5" label="HB1"
                                             required="true" disabled="#{!patient.hasHb3()}"/>
                            </p:inplace>
                        </center>
                    </p:column>
                </p:dataTable><br/>
                <p:commandButton id="bottomSave" action="#{hbBean.save()}" 
                                 value="Salvar" disabled="#{hbBean.activeBottom()}"/>
                <p:separator/>
                <p:commandButton value="Gerar Anamnese" onclick="anamneseC.show();"/>
                <p:commandButton value="Gerar Receituário" onclick="recipieD.show();"/>
            </h:panelGroup>
        </h:form>    
    </ui:define>
    
    <ui:define name="modals">
        <p:dialog header="Atenção! Operação complicada" widgetVar="recipieD">
            <h:form>
                <h:panelGrid columns="2">
                    <h:outputLabel for="concenF" value="Concentração: (mg/ml)"/>
                    <h:inputText id="concenF" value="#{hbBean.concentration}"/>
                    <h:outputLabel for="consultationF" value="Data da consulta:"/>
                    <p:calendar id="consultationF" value="#{hbBean.consultationDate}"/>
                    <p:commandButton value="Gerar Receituário" action="#{hbBean.generatePrescription()}" 
                                     ajax="false" onclick="this.form.target='_blank';"/>
                    <p:commandButton value="Cancelar" onclick="recipieD.hide();"/>
                </h:panelGrid>
            </h:form>
        </p:dialog>
        <h:form>
            <p:confirmDialog widgetVar="anamneseC" header="Atenção! Operação complicada"
                             message="Tem certeza que deseja gerar este formulário?">
                <p:commandButton value="Gerar PDF" action="#{hbBean.generateAnamnese()}" oncomplete="anamneseC.hide()"
                                 onclick="this.form.target='_blank';" ajax="false"/>
                <p:commandButton value="Cancelar" onclick="anamneseC.hide();"/>
            </p:confirmDialog>
        </h:form>
    </ui:define>
    
</ui:composition>
